package com.itheima.Vue.web.manager.web;

import com.itheima.Vue.web.manager.service.ContactService;
import com.itheima.Vue.web.manager.pojo.Contact;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

@WebServlet("/UpdateServlet")
public class UpdateServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            // 发起请求
            request.setCharacterEncoding("utf-8");
            Map<String, String[]> map = request.getParameterMap();
            Contact contact = new Contact();
            BeanUtils.populate(contact,map);

            //2.业务处理
            ContactService service = new ContactService();
            service.updateContact(contact);

            //3.重定向
            response.sendRedirect("PageQueryServlet");
        } catch (Exception e) {
            e.printStackTrace();

        }


    }
}